<?php
declare (strict_types=1);

namespace app\admin\controller\business;

use app\admin\controller\admin\Admin;
use app\common\model\AdminAdmin;
use app\common\model\BusinessCourse;
use app\common\model\SchoolIndex;
use think\facade\Request;
use app\common\service\BusinessOrder as S;
use app\common\model\BusinessOrder as M;

class Order extends \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        $school = SchoolIndex::field('id,school_name')->select();
        $course = BusinessCourse::field('id,course_name')->select();
        return $this->getAuto($this->fetch('', ['school' => $school, 'course' => $course]), M::getList());
    }

    // 添加
    public function add()
    {
        return $this->getAuto($this->fetch(), S::goAdd(Request::post()));
    }

    // 编辑
    public function edit($id)
    {
        return $this->getAuto($this->fetch('', ['model' => M::find($id)]), S::goEdit(Request::post(), $id));
    }

    // 状态
    public function status($id)
    {
        return $this->getJson(S::goStatus(Request::post('status'), $id));
    }

    // 删除
    public function remove($id)
    {
        return $this->getJson(S::goRemove($id));
    }

    // 批量删除
    public function batchRemove()
    {
        return $this->getJson(S::goBatchRemove(Request::post('ids')));
    }

    // 回收站
    public function recycle()
    {
        return $this->getAuto($this->fetch(), S::goRecycle());
    }

    public function addOrder($id = 1)
    {
        return $this->getJson(S::addOrder(Request::post(''), $id));
    }

}
